﻿@model ContentResourceDto
@{
    var x = @Html.EasyUi();
}
<script type="text/javascript">
    var video_tag_close = function () {
        $("#text_video_tag_add").val("");
        $("#text_video_tag_add").focus();
    }
    var video_tag_save = function () {
        var value = $("#text_video_tag_add").val();
        if (!value) {
            $.easyui.warn("值不能为空");
            return;
        }
        if (value.length >= 10) {
            $.easyui.warn("值输入过长，不能超过50位");
            return;
        }

        var getValues = function () {
            var cache = [];
            var count = 0;
            $("form[id=form_video] input[name=TagList]").each(function () {
                cache[count] = $(this).val();
                count++;
            });
            return cache;
        }

        var values = getValues();
        for (var i = 0; i < values.length; i++) {
            if (value === values[i]) {
                $.easyui.warn("该值已存在");
                return;
            }
        }
        var html = video_tag_gethtml(value);
        $("#div_video_tag_preview").append(html);
        video_tag_close();
    }

    var video_tag_gethtml = function (value) {
        var li = '<div onclick="video_tag_del(this)">';
        li += '<input type="text" name="TagList" value="' + value + '" hidden/>';
        li += '<span class="tagconfig-option">' + value + '</span>';
        li += '</div>';
        return li;
    }

    var video_tag_del = function (obj) {
        $(obj).remove();
    }

    var video_tag_refresh = function () {
        video_tag_close();
        var getHistoryHtml = function () {
            var html = "";
            var values = $("#div_video_tag_history").val();
            var valueList = values.split(",");
            for (var i = 0; i < valueList.length; i++) {
                if (!valueList[i])
                    continue;
                html += video_tag_gethtml(valueList[i]);
            }
            return html;
        }
        $("#div_video_tag_preview").html(getHistoryHtml());
    }


    //视频单封面点击
    var radio_video_singleBannerType_click = function () {
        $("#text_video_bannerType").val(@(ContentResourceBannerType.Single.Value()));
        $.easyui.refreshPanel("panel_video_banner", "/contentResources/content/SingleBannerEdit?Id=@(Model.SingleBanner.Id)");
    }
//视频三封面点击
    var radio_video_threeBannerType_click = function () {
        $("#text_video_bannerType").val(@(ContentResourceBannerType.Three.Value()));
        $.easyui.refreshPanel("panel_video_banner", "/contentResources/content/MultiBannersEdit?ids=@(Model.MultiBanners.Select(t => t.Id).Join())");
    }

    var checkbox_video_isRegularPublication_click = function () {
        var isRegularPublication = $("#text_video_isRegularPublication").val();
        switch (isRegularPublication) {
        case "true":
        case "True":
            $("#text_video_isRegularPublication").val('False');
            $("#div_video_publicationTime").css("display", "none");
            return;
        default:
            $("#text_video_isRegularPublication").val('True');
            $("#div_video_publicationTime").css("display", "block");
            return;
        }
    }

    var save_before_video_draft = function (data) {
        $("#text_video_state").val(@(ContentResourceState.Draft.Value()));
        return data;
    }
    var save_before_video_publish = function (data) {
        $("#text_video_state").val(@(ContentResourceState.Publish.Value()));
        return data;
    }
</script>
<div class="divForm">
    <div class="formtitle">内容资源管理【视频】</div>
    @using (x.Form("form_video").AddClass("form").Action("/contentResources/content/save").AddStyle("overflow-x", "hidden").Begin())
    {
        <dl style="width: 100%">
            <dt>@Html.LabelFor(t => t.Title)</dt>
            <dd style="width: 80%">
                @x.TextBox(t => t.Title).Width(100, true)
            </dd>
        </dl>
        <div class="line"></div>
        <dl style="width: 100%; height: 75px;">
            <dt style="width: 100%;">
                @Html.LabelFor(t => t.Tags)
                <input type="text" value="@(Model.Tags)" id="div_video_tag_history" hidden />
                <input type="text" id="text_video_tag_add" style="width: 200px; margin-top: 3px;" />
                @x.Button("保存").Icon("icon-ok").Plain().Click("video_tag_save()")
                @x.Button("取消").Icon("icon-cancel").Plain().Click("video_tag_close()")
                @x.Button("重置").Icon("icon-refresh").Plain().Click("video_tag_refresh()")
            </dt>
            <dd style="width: 100%; height: 50px;">
                <div class="line"></div>
                <div style="width: 100%;" id="div_video_tag_preview">
                    @foreach (var item in Model.TagList)
                    {
                        <div onclick="video_tag_del(this)">
                            <input type="text" name="TagList" value="@(item)" hidden />
                            <span class="tagconfig-option">@(item)</span>
                        </div>
                    }
                </div>
            </dd>
        </dl>
        <div class="line"></div>
        <dl style="width: 100%">
            <dt>@Html.LabelFor(t => t.Video)</dt>
            <dd style="width: 80%">
                @Html.Ui().Attachment().SingleEdit(t => t.Video, Model.Video, FileType.Video)
            </dd>
        </dl>
        <div class="line"></div>
        <dl style="width: 100%">
            <dt>@Html.LabelFor(t => t.BriefIntroduction)</dt>
            <dd style="width: 80%">
                @x.TextBox(t=>t.BriefIntroduction).MultiLine(1080,200)
            </dd>
        </dl>
        <div class="line"></div>
        <dl style="width: 100%">
            <dt>
                @Html.Label("封面")
                <input type="text" name="BannerType" id="text_video_bannerType" value="@(Model.BannerType.Value() ?? ContentResourceBannerType.Single.Value())" hidden="" />
            </dt>
            <dd style="width: 80%">
                <label>
                    <input onclick="radio_video_singleBannerType_click();" type="radio" name="ContentResourceBannerType" @(Model.BannerType == null || Model.BannerType == ContentResourceBannerType.Single ? "checked=\"\"" : "")>@(ContentResourceBannerType.Single.Description())
                </label>
                <label>
                    <input onclick="radio_video_threeBannerType_click();" type="radio" name="ContentResourceBannerType" @(Model.BannerType == ContentResourceBannerType.Three ? "checked=\"\"" : "")>@(ContentResourceBannerType.Three.Description())
                </label>
                @using (x.Panel().Id("panel_video_banner").Center().AddClass("content").Begin())
                {
                    switch (Model.BannerType)
                    {
                        case null:
                        case ContentResourceBannerType.Single:
                            @Html.Action("SingleBannerEdit", "Content", new { resources = Model.SingleBanner })
                            break;
                        case ContentResourceBannerType.Three:
                            @Html.Action("InitMultiBannersEdit", "Content", new { resourceses = Model.MultiBanners })
                            break;
                    }
                 }
            </dd>
        </dl>
        if (Model.State != ContentResourceState.Publish)
        {
            <div class="line"></div>
            <dl style="width: 100%">
                <dt>
                    <input type="text" name="IsRegularPublication" id="text_video_isRegularPublication" value="@((Model.IsRegularPublication ?? false) ? "True" : "False")" hidden=""/>
                </dt>
                <dd style="width: 80%">
                    <label style="width: 10%">
                        <input onclick="checkbox_video_isRegularPublication_click();" type="checkbox" @(Model.IsRegularPublication == true ? "checked=\"\"" : "")>是否定时发表
                    </label>
                    <div id="div_video_publicationTime" @(Html.Raw(Model.IsRegularPublication != true ? "style=\"display: none\"" : ""))>
                        @x.TextBox(t => t.PublicationTime).Width(200)
                    </div>
                </dd>
            </dl>
        }
        else
        {
            @Html.HiddenFor(t => t.IsRegularPublication)
            @Html.HiddenFor(t => t.IsRegularPublication)
        }
        <div class="line"></div>
        <dl>
            <dt>@Html.Label("分类")</dt>
            <dd>
                @x.ComboTree("CategoriyId", "CategoriyId", "/contentResources/Category/ComboTree", Model.CategoriyId.ToString()).Width(200)
            </dd>
        </dl>
        <input type="text" name="State" id="text_video_state" value="@(Model.State)" hidden="" />
        @Html.HiddenFor(t => t.Type)
        @Html.HiddenFor(t => t.RichText)
        @Html.HiddenFor(t => t.SystemBanners)
        @Html.HiddenFor(t => t.PictureDtos)
        @Html.HiddenFor(t => t.CreationTime)
        @Html.HiddenFor(t => t.CreatorId)
        @Html.HiddenFor(t => t.LastModificationTime)
        @Html.HiddenFor(t => t.LastModifierId)
        @Html.HiddenFor(t => t.IsDeleted)
        @Html.HiddenFor(t => t.Version)
        @Html.HiddenFor(t => t.Id)
        @Html.AntiForgeryToken()
     }
</div>
<div id="dialogButtons_Article" style="float: right;">
    @if (Model.State != ContentResourceState.Publish)
    {
        @x.Button("保存草稿").Icon("icon-save").Width(90).Submit("save_before_video_draft", "save_after", "form_video")
        @x.Button("发  表").Icon("icon-ok").Width(90).Submit("save_before_video_publish", "save_after", "form_video")
    }
    else
    {
        @x.Button("保 存").Icon("icon-save").Width(90).Submit("", "save_after", "form_video")
    }
    @x.DialogButton("关 闭").Icon("icon-cancel").Width(90).CloseDialog()
</div>